package com.zxn.rxbus.demo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.hwangjr.rxbus.RxBus
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.hwangjr.rxbus.thread.EventThread
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        RxBus.get().register(this)

        btn_page_second.setOnClickListener(View.OnClickListener {
            startActivity(Intent(this, SecondActivity::class.java))
        })
    }

    override fun onDestroy() {
        super.onDestroy()
        RxBus.get().unregister(this)
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = [Tag(IRxBusTags.CLOSE_ALL)])
    fun onEvent(s: Any) {
        Log.i(TAG, "onEvent: $s")
        finish()
    }

    companion object{
        val TAG = "MainActivity"
    }
}